package com.ahcg

import scala.io.{BufferedSource, Source}

object Demo5 {

  def main(args: Array[String]): Unit = {
    // 从磁盘中读取文件，并且把结果转为List集合
    val source: BufferedSource = Source.fromFile("data/2020phonelocation.txt")

    val phone: List[String] = source.getLines().toList
    phone.foreach(println)

    /**
     * 计算指定地区的号码的记录数
     *
     * @param area
     * @return
     */
    def count(area: String): Int = {
      var sum = 0
      for (a <- phone; if a.contains(area)) {
        sum += 1
      }
      sum
    }

    println(count("合肥"))

  }
}
